/*
 * 文件名：DeleteHisData.java	 
 * 时     间：下午3:39:43
 * 作     者：liyf       
 * 版     权： 2012-2022 湖南智软网络科技, 公司保留所有权利.
 * 联     系：http://www.073586.com/
 */
package com.schedule.log;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.cz073586.tools.util.Log4jUtil;
import com.local.dao.hismappers.CarParkInCopyMapper;
import com.local.dao.hismappers.CarParkOutCopyMapper;
import com.local.dao.hismappers.LocalPayBillMapper;
import com.local.model.CarParkInCopyExample;
import com.local.model.CarParkOutCopyExample;
import com.local.model.LocalPayBillExample;

/**
 * 类描述:删除两个月外历史数据
 * 
 * @ClassName: DeleteHisData
 * @author liyf
 * @date 2016年7月3日 下午3:39:43
 */
@Service
@EnableScheduling
public class DeleteHisData
{
	private final static Log4jUtil log = Log4jUtil
			.getLog4j(DeleteHisData.class);
	@Autowired
	private CarParkInCopyMapper carParkInCopyMapper;
	
	@Autowired
	private CarParkOutCopyMapper carParkOutCopyMapper;
	
	@Autowired
	private LocalPayBillMapper payBillMapper;
	
	@Scheduled(cron = "0 0 3 * * ?")
	public void clearHis()
	{
		try
		{
			Calendar date = Calendar.getInstance();
			date.add(Calendar.MONTH, -1);
			
			// 删除进场，保留两个月数据
			CarParkInCopyExample inEx = new CarParkInCopyExample();
			inEx.or().andCreateTimeLessThan(date.getTime());
			carParkInCopyMapper.deleteByCondition(inEx);
			
			// 删除流水
			LocalPayBillExample billEx = new LocalPayBillExample();
			billEx.or().andPayTimeLessThan(date.getTime());
			payBillMapper.deleteByCondition(billEx);
			
			// 删除出场
			CarParkOutCopyExample outEx = new CarParkOutCopyExample();
			outEx.or().andCreateTimeLessThan(date.getTime());
			carParkOutCopyMapper.deleteByCondition(outEx);
			
		} catch (Throwable t)
		{
			log.error("删除历史数据", t);
		}
	}
	
}
